﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ShaderEffectsLibrary;

namespace Behavior
{
    /// <summary>
    /// 自定议行为
    /// </summary>
    public class BehaviorWithCommand : System.Windows.Interactivity.Behavior<FrameworkElement>
    {
        InverseColor inverseColor;

        public BehaviorWithCommand()
        {
            inverseColor = new InverseColor();
        }

        /// <summary>
        /// 将行为附加到对像
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();
            ///附加关联对像时加上Mouse处理事件
            this.AssociatedObject.MouseEnter += new MouseEventHandler(AssociatedObject_MouseEnter);
        }

        void AssociatedObject_MouseEnter(object sender, MouseEventArgs e)
        {
                    this.AssociatedObject.Effect =
             this.AssociatedObject.Effect == null ?
             inverseColor
             :
             null;
        }


        /// <summary>
        /// 行为与其 AssociatedObject 分离时（但在它实际发生之前）调用。
        /// </summary>
        protected override void OnDetaching()
        {
            base.OnDetaching();
            ///分设关联对像时加上Mouse处理事件
            this.AssociatedObject.MouseLeave -= new MouseEventHandler(AssociatedObject_MouseEnter);
        }


    }

}
